import java.util.ArrayList;

public class MiniRE{
	public static void main(String[] args){
		String scriptfile = args[0]; 
		//start the scanner
		Scanner scanner = new Scanner("MinRE_LangSpec.txt", scriptfile);
		//getting tokens one by one. If EOF, getNextToken returns null.
		Interpreter interpreter = new Interpreter(scanner.getAllTokens());
		if(!interpreter.MiniREProgram()){ System.out.println("Compile-time Error Detected - Syntax"); }
		//execute each instruction through the interpreter
		else{
			for(ArrayList<String> statement:interpreter.getFindStatements()){
				System.out.println("Found following occurences of "+statement.get(0)+" in "+statement.get(1));
				for(String match:interpreter.find(statement.get(0), statement.get(1))){System.out.println(match);}
			}
			for(ArrayList<String> statement: interpreter.getReplaceStatements()){
				System.out.println("Replacing matches of "+statement.get(0)+" with "+statement.get(1)+" in "+statement.get(2));
				interpreter.replace(statement.get(0), statement.get(1),statement.get(2));
			}
		}//end else
	}//end method main
}//end MiniRE class def